package com.globallogic.restdemo.services;

import com.globallogic.restdemo.dao.UserDao;
import com.globallogic.restdemo.dto.User;
import com.globallogic.restdemo.utils.UserValidator;
import com.globallogic.restdemo.utils.Validator;

import java.util.Collection;

public class UserService {

    private Validator<User> validator;
    private UserDao userDao;

    public UserService(){
        validator = new UserValidator();
        userDao = UserDao.getInstance();
    }

    public Collection<User> getAllUsers(){
        return  userDao.getAllUsers();
    }

    public User getUserById(long id){
        return userDao.getUserById(id);
    }

    public void addUser(User user){
        if (validator.isValid(user))
            userDao.addUser(user);
    }

    public void updateUser(User user){
        if (validator.isValid(user))
            userDao.updateUser(user);
    }

    public void removeAllUsers(){
        userDao.removeAllUsers();
    }

    public void removeUserById(long id){
        userDao.removeUserById(id);
    }
}
